package indi.zhifa.study2025.class004.imgserv.config;

import indi.zhifa.study2025.class004.imgserv.utils.ConstantUtil;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {
    @Bean(name = ConstantUtil.PICTURE_VEC_CAL_QUEUE)
    public Queue pictureQue() {
        return new Queue(ConstantUtil.PICTURE_VEC_CAL_QUEUE,true);
    }

    @Bean(name = ConstantUtil.PICTURE_EXCHANGE)
    public DirectExchange pictureExchange() {
        return new DirectExchange(ConstantUtil.PICTURE_EXCHANGE);
    }

    @Bean
    public Binding bindingQue1(@Qualifier(ConstantUtil.PICTURE_VEC_CAL_QUEUE) Queue myQueue, @Qualifier(ConstantUtil.PICTURE_EXCHANGE) DirectExchange exchange) {
        return BindingBuilder.bind(myQueue).to(exchange).with(ConstantUtil.PICTURE_VEC_CAL_KEY);
    }

    @Bean
    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
        rabbitTemplate.setReplyTimeout(3000);
        rabbitTemplate.setExchange(ConstantUtil.PICTURE_EXCHANGE);
        return rabbitTemplate;
    }
}
